package org.cloud.consumer.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.cloud.consumer.service.AsyncService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

/**
 * @author hjx
 * @title: AsyncServiceImpl
 * @description: TODO
 * @date 2022/8/5
 */
@Slf4j
@Service
public class AsyncServiceImpl implements AsyncService {
    @Override
    @Async("taskThreadPool")
    public CompletableFuture<String> executeAsync(int index) {
        log.info("start executeAsync "+index);
        try{
            Thread.sleep(1000);
        }catch(Exception e){
            e.printStackTrace();
        }
        log.info("end executeAsync "+index);
        return CompletableFuture.completedFuture("success "+index);
    }

}
